﻿using HelloWorld.RobotFights;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RobotsFight.RobotImplementation
{
    public class RubanenkoRobot : Robot
    {
        public RubanenkoRobot(String name,ConsoleColor color)
        {
            _name  = name;
            _color = color;
        }

        public override void DoStep(Func<int, int, Robot, int> checkEmpty)
        {
            Random rnd = new Random();

            int q = rnd.Next(1, 5);
            if (q == 1)
                MoveRight(1);
            if (q == 2)
                MoveLeft(1);
            if (q == 3)
                MoveBottom(1);
            if (q == 4)
                MoveTop(1);
        }

        private void MoveLeft(int interval)
        {
            x -= interval;
            x = Math.Max(x, 0);
        }
        private void MoveRight(int interval)
        {
            x += interval;
            x = Math.Min(x, Console.BufferWidth - 1);
        }
        private void MoveTop(int interval)
        {
            y -= interval;
            y = Math.Max(y, 0);
        }
        private void MoveBottom(int interval)
        {
            y += interval;
            y = Math.Min(y, Console.BufferHeight - 1);
        }
    }
}
